package mi.payment.utils;

import android.text.TextUtils;

public class AllianceUtil {

    public static String decode250(String value) {
        value = value.replaceAll("0030", "00");
        value = value.replaceAll("0031", "01");
        value = value.replaceAll("0032", "02");
        value = value.replaceAll("0033", "03");
        value = value.replaceAll("0034", "04");
        value = value.replaceAll("0035", "05");
        return value;
    }

    public static String encode250(String value) {
        if (value.length() % 2 != 0) return value;
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < value.length() / 2; i++) {
            String temp = value.substring(i * 2, (i + 1) * 2);
            boolean equal = TextUtils.equals("00", temp) || TextUtils.equals("01", temp) ||
                    TextUtils.equals("02", temp) || TextUtils.equals("03", temp) ||
                    TextUtils.equals("04", temp) || TextUtils.equals("05", temp);
            if (equal) {
                int parseInt = Integer.parseInt(temp, 16);
                parseInt = parseInt + 30;
                sb.append("00" + parseInt);
            } else {
                sb.append(temp);
            }
        }
        return sb.toString();
    }

}
